package com.choichumgming.rentcat.web.rpc;


import com.choichumgming.rentcat.common.api.CommonResult;
import com.choichumgming.rentcat.model.PmsProduct;
import com.choichumgming.rentcat.service.PmsProductFeignApi;
import com.choichumgming.rentcat.service.PmsProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PmsProductFeignClient
 * @Description : 商品管理PmsProductFeignClient
 * @Author : choichumgming
 * @Date : 27/2/2020 22:16
 */
@Controller
@Api(tags = "PmsProductFeignClient", description = "商品管理api接口实现")
@RequestMapping("/api")
public class PmsProductFeignClient implements PmsProductFeignApi {
    @Autowired
    private PmsProductService productService;


    @Override
    @ApiOperation("根据商品id查询商品")
    @RequestMapping(value = "/product")
    @ResponseBody
    public CommonResult<PmsProduct> getProduct(@RequestParam(value = "productId") Long productId) {
        PmsProduct product= productService.getProduct(productId);
        return CommonResult.success(product);
    }

    @Override
    @ApiOperation("释放出租情况")
    @RequestMapping(value = "/releaseRentLock")
    @ResponseBody
    public CommonResult releaseRentLock(@RequestParam("productId")Long productId) {
        int result = productService.updateRentStatus(productId, 0);
        return  CommonResult.success(result);
    }

    @Override
    @ApiOperation("锁定商品")
    @RequestMapping(value = "/lockProduct")
    @ResponseBody
    public CommonResult lockProduct(@RequestParam("productId")Long productId) {
        int result = productService.updateRentStatus(productId, 1);
        return  CommonResult.success(result);
    }
}
